package com.gelsanalyzer.ui.swing.command;

import java.awt.event.*;
import java.beans.*;

import javax.swing.*;

import org.apache.log4j.*;

import com.gelsanalyzer.business.*;
import com.gelsanalyzer.core.*;
import com.gelsanalyzer.mvc.controller.*;

public class GetCourseEntryItemCommand extends AbstractAction implements Command {
    private static final Logger log = Logger.getLogger(GetCourseEntryItemCommand.class);

    private IController controller;

    public GetCourseEntryItemCommand(String label, IController controller) {
        this(label, null, null, null, controller);
    }

    public GetCourseEntryItemCommand(String label,
                             ImageIcon icon,
                             String desc,
                             Integer mnemonic,
                             IController controller) {
        super(label, icon);
        putValue(SHORT_DESCRIPTION, desc);
        putValue(MNEMONIC_KEY, mnemonic);
        this.controller = controller;
    }

    public void setController(IController controller) {
        this.controller = controller;
    }

    public void Execute() {
    }

    public void actionPerformed(ActionEvent arg0) {
        log.debug("Entered actionPerformed(ActionEvent) about "
                + "to call controller.propertyChange(PropertyChangeEvent)");
        // May need to put in a conditional statement below depending on what
        // the source object actually is... for now, we know that the
        // arg0.getSource() object is a JComboBox
        Course course = (Course)((JComboBox)arg0.getSource()).getSelectedItem();
        
        AddCourseCommand acc = (AddCourseCommand)ActionFactory.getAddCourse();
        acc.setEnabled(true);
        acc.setCourse(course);
        
        RemoveCourseCommand rcc = (RemoveCourseCommand)ActionFactory.getRemoveCourse();
        rcc.setEnabled(true);
        rcc.setCourse(course); 
        
        controller.propertyChange(new PropertyChangeEvent(this,
            IController.APP_SELECTED_A_COURSE, null, course));
      
    }

}
